﻿<Window x:Class="AlertSettingsWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Co9320="clr-namespace:Co9320"
        Icon="../Icons/application.ico"
        Title="通知設定" SizeToContent="Height" WindowStartupLocation="CenterOwner" 
        Width="440"
        ResizeMode="NoResize" ShowInTaskbar="False">

    <Window.BindingGroup>
        <BindingGroup />
    </Window.BindingGroup>

    <Window.CommandBindings>
        <CommandBinding Command="{x:Static Co9320:AlertSettingsWindow.SendMailCommand}" Executed="SendMailCommandBinding_Executed" CanExecute="SendMailCommandBinding_CanExecute" />
        <CommandBinding Command="{x:Static Co9320:AlertSettingsWindow.PlaySoundCommand}" Executed="PlaySoundCommandBinding_Executed" CanExecute="PlaySoundCommandBinding_CanExecute" />
        <CommandBinding Command="{x:Static Co9320:AlertSettingsWindow.SetDefaultCommand}" Executed="SetDefaultCommandBinding_Executed" CanExecute="SetDefaultCommandBinding_CanExecute" />
    </Window.CommandBindings>
    
    <Window.DataContext>
        <Co9320:UserSettings />
    </Window.DataContext>
    

    <Window.Resources>
        <Co9320:IntegerToStringConverter x:Key="IntegerToStringConverter" />

        <!-- TODO 共通化 -->
        <Style x:Key="ImageButtonBaseStyle" TargetType="{x:Type ButtonBase}">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
            <Setter Property="HorizontalContentAlignment" Value="Center"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <ContentPresenter Name="Presenter" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" RecognizesAccessKey="True" RenderTransformOrigin="0.5,0.5"/>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsPressed" Value="True">
                                <Setter Property="RenderTransform" TargetName="Presenter">
                                    <Setter.Value>
                                        <TranslateTransform X="1" Y="1"/>
                                    </Setter.Value>
                                </Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource ImageButtonBaseStyle}"/>

    </Window.Resources>


    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="40" />
        </Grid.RowDefinitions>
        <TabControl>
            <TabItem Header="通知方法">
                <Grid Name="DefaultAlertGrid">
                    <Grid.BindingGroup>
                        <BindingGroup />
                    </Grid.BindingGroup>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="40" />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition Height="40" />
                    </Grid.RowDefinitions>

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="22" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <StackPanel Grid.ColumnSpan="2">
                        <TextBlock Margin="5" Name="DescriptionTextBox" />
                    </StackPanel>

                    <Image Grid.Row="1" Margin="5 0 0 0" Source="../Images/shadow/card_address.png" Stretch="None" VerticalAlignment="Center" Width="16" Height="16" />
                    <Image Grid.Row="2" Margin="5 0 0 0" Source="../Images/shadow/balloon_left.png" Stretch="None" VerticalAlignment="Center" Width="16" Height="16" />
                    <Image Grid.Row="3" Margin="5 0 0 0" Source="../Images/shadow/application__arrow.png" Stretch="None" VerticalAlignment="Center" Width="16" Height="16" />
                    <Image Grid.Row="4" Margin="5 0 0 0" Source="../Images/shadow/mail.png" Stretch="None" VerticalAlignment="Center" Width="16" Height="16" />
                    <Image Grid.Row="5" Margin="5 0 0 0" Source="../Images/shadow/music.png" Stretch="None" VerticalAlignment="Center" Width="16" Height="16" />

                    <CheckBox Grid.Row="1" Grid.Column="1" Margin="5" IsChecked="{Binding Path=AlertByWindow}" VerticalAlignment="Center">通知ウィンドウ</CheckBox>
                    <CheckBox Grid.Row="2" Grid.Column="2" Margin="5" IsChecked="{Binding Path=AlertByBalloon}" VerticalAlignment="Center">バルーン表示</CheckBox>
                    <CheckBox Grid.Row="3" Grid.Column="3" Margin="5" IsChecked="{Binding Path=AlertByBrowser}" VerticalAlignment="Center">生放送のページへ移動</CheckBox>
                    <CheckBox Grid.Row="4" Grid.Column="4" Margin="5" IsChecked="{Binding Path=AlertByMail}" VerticalAlignment="Center">メール送信</CheckBox>
                    <CheckBox Grid.Row="5" Grid.Column="5" Margin="5" IsChecked="{Binding Path=AlertBySound}" VerticalAlignment="Center">サウンド再生</CheckBox>

                    <StackPanel Grid.Row="6" Grid.ColumnSpan="2" HorizontalAlignment="Right"  Orientation="Horizontal" Margin="5 5 0 5" VerticalAlignment="Bottom">
                        <Button Content="既定の設定にする" Height="28"  Padding="3"
                                Command="{x:Static Co9320:AlertSettingsWindow.SetDefaultCommand}" 
                                 />
                    </StackPanel>

                </Grid>

            </TabItem>
            <TabItem Header="ウィンドウ" Visibility="Collapsed">
                
            </TabItem>
            <TabItem Header="バルーン" Visibility="Collapsed">

            </TabItem>
            <TabItem Header="Webブラウザ">
                <StackPanel>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="90" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Label Content="Webブラウザ:" VerticalAlignment="Center" />
                        <Label Content="引数:" Grid.Row="1" VerticalAlignment="Center" />
                        <Grid Grid.Column="1" Margin="0 5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="40"  />
                            </Grid.ColumnDefinitions>
                            <TextBox Text="{Binding Path=Browser.Path}" Name="BrowserPathTextBox" />
                            <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                                <Button Padding="0" Style="{StaticResource ImageButtonStyle}"
                                        Click="BrowserPathButton_Click">
                                    <Image Margin="0" Source="../Images/shadow/folder_open.png" Width="16" Height="16"
                                           ToolTip="開く" />
                                </Button>
                                <Button Padding="0" Style="{StaticResource ImageButtonStyle}" Margin="3 0 0 0"
                                        Click="BrowserPathClearButton_Click">
                                    <Image Margin="0" Source="../Images/shadow/cross.png" Width="16" Height="16"
                                           ToolTip="削除" />
                                </Button>
                            </StackPanel>
                        </Grid>
                        <TextBox Grid.Row="1" Grid.Column="1" Margin="0 5"
                                 Text="{Binding Path=Browser.Args}" Name="BrowserArgsTextBox" />

                    </Grid>
                    <TextBlock TextWrapping="Wrap" Text="* 引数中の「{url}」は、開くURLに置き換えられます。
その他の使用できる引数 
{live_id}: Live Id, {station_id}: 放送局ID, {title}: 放送タイトル, {station_name}: 放送局名
" Margin="15 0 0 0" />
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="120" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="表示遅延(ミリ秒):" Margin="0 5" VerticalAlignment="Center" />
                        <TextBox Grid.Column="1" Text="{Binding Path=Browser.Delay, Converter={StaticResource IntegerToStringConverter}}" VerticalAlignment="Center" HorizontalAlignment="Left" Width="100" />
                    </Grid>
                    <TextBlock TextWrapping="Wrap" Text="* アラート設定による表示時のみ有効" Margin="15 0 0 0" />
                </StackPanel>
            </TabItem>
            <TabItem Header="メール">
                <StackPanel>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Label Content="送信先 E-mail:" VerticalAlignment="Center" />
                        <Label Grid.Row="1" Content="送信元 E-mail:" VerticalAlignment="Center" />
                        <Label Grid.Row="2" Content="SMTPサーバー:" VerticalAlignment="Center" />
                        <Label Grid.Row="3" Content="ポート:" VerticalAlignment="Center" />
                        <Label Grid.Row="4" Content="エンコード形式:" VerticalAlignment="Center" />
                        <TextBox Grid.Column="1" Margin="0 5" Text="{Binding Path=Mail.ToAddress}" Name="MailToAddressTextBox" />
                        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Mail.FromAddress}" Name="MailFromAddressTextBox" Margin="0 5" />
                        <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=Mail.SmtpServer}" Name="MailSmtpServerTextBox" Margin="0 5" />
                        <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=Mail.Port, Converter={StaticResource IntegerToStringConverter}}" Name="MailPortTextBox" Margin="0 5" Width="50" HorizontalAlignment="Left" />
                        <ComboBox Grid.Row="4" Grid.Column="1" Margin="0 5" Width="150" HorizontalAlignment="Left"
                                  ItemsSource="{Binding Path=Mail.Encodings, Mode=OneWay}"
                                  SelectedValue="{Binding Path=Mail.Encoding}"
                                  >
                        </ComboBox>
                        <CheckBox Grid.Row="5" Grid.ColumnSpan="2" Content="SSL通信を使用する" IsChecked="{Binding Path=Mail.EnableSsl}" VerticalAlignment="Center" Margin="5" />
                    </Grid>
                    <Expander Header="SMTP認証" IsExpanded="False">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Label Content="ユーザー名:" VerticalAlignment="Center" />
                            <Label Grid.Row="1" Content="パスワード:" VerticalAlignment="Center" />
                            <TextBox Grid.Column="1" Margin="0 5" 
                                     Text="{Binding Path=Mail.UserName}" Name="MailUserNameTextBox"/>
                            <PasswordBox Grid.Row="1" Grid.Column="1" Margin="0 3"
                                         Name="MailPasswordTextBox" />
                        </Grid>
                    </Expander>
                    <Button Content="テスト送信" HorizontalAlignment="Right" 
                            Height="28" Margin="0 5" Width="80"
                            Command="{x:Static Co9320:AlertSettingsWindow.SendMailCommand}" />
                </StackPanel>
            </TabItem>
            <TabItem Header="サウンド">
                <StackPanel>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="110" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Label Content="サウンドファイル:" VerticalAlignment="Center" />
                        <Grid Grid.Column="1" Margin="0 5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="40"  />
                            </Grid.ColumnDefinitions>
                            <TextBox Text="{Binding Path=Sound.Path}" Name="SoundPathTextBox" />
                            <StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
                                <Button Padding="0" Style="{StaticResource ImageButtonStyle}"
                                        Click="SoundPathButton_Click">
                                    <Image Margin="0" Source="../Images/shadow/folder_open.png" Width="16" Height="16"
                                           ToolTip="開く" />
                                </Button>
                                <Button Padding="0" Style="{StaticResource ImageButtonStyle}" Margin="3 0 0 0"
                                        Click="SoundPathClearButton_Click">
                                    <Image Margin="0" Source="../Images/shadow/cross.png" Width="16" Height="16"
                                           ToolTip="削除" />
                                </Button>
                            </StackPanel>
                        </Grid>
                    </Grid>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <!--<Slider VerticalAlignment="Center" Margin="5" />-->
                        <Button Content="再生" HorizontalAlignment="Right"
                                Grid.Column="1"
                            Height="28" Margin="0 5" Width="80"
                            Command="{x:Static Co9320:AlertSettingsWindow.PlaySoundCommand}" />
                    </Grid>
                </StackPanel>
            </TabItem>
        </TabControl>
        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="0 5 5 5" VerticalAlignment="Bottom" HorizontalAlignment="Right">
            <Button Content="OK" Width="80" Height="28" Margin="5 0" IsDefault="True" Click="OkButton_Click" />
            <Button Content="キャンセル" Width="80" Height="28" IsCancel="True" Click="CancelButton_Click" />
        </StackPanel>

    </Grid>
</Window>
